﻿namespace HiMap.Carto
{
    using HiMap.Base;
    using System;
    using System.Text;

    public class KRasterLayerClass : HiMapPtrClass, IKRasterLayer, ILayer, IHiMapPtr
    {
        public KRasterLayerClass(int InPtr, bool Used)
        {
            base.m_InPtr = InPtr;
            base.m_Used = Used;
        }

        ~KRasterLayerClass()
        {
            if (!base.m_Used)
            {
                VC.KWG_LAYER_DELETE(base.m_InPtr);
            }
        }

        public static IKRasterLayer Open(string KRasterName)
        {
            int inPtr = VC.KWG_KRASTER_OPEN(new StringBuilder(KRasterName));
            if (inPtr > 0)
            {
                return new KRasterLayerClass(inPtr, false);
            }
            return null;
        }

        string ILayer.Caption
        {
            get
            {
                StringBuilder builder = new StringBuilder(0x100);
                VC.KWG_LAYER_GET_CAPTION(base.m_InPtr, builder);
                return builder.ToString();
            }
            set
            {
                VC.KWG_LAYER_SET_CAPTION(base.m_InPtr, new StringBuilder(value));
            }
        }

        IClass ILayer.Class
        {
            get
            {
                return null;
            }
            set
            {
            }
        }

        Map ILayer.Map
        {
            get
            {
                return new Map(VC.KWG_LAYER_GET_MAP(base.m_InPtr), true);
            }
        }

        double ILayer.MaxVisibleScale
        {
            get
            {
                double scale = 0;
                VC.KWG_LAYER_GET_MAXSCALE(base.m_InPtr, ref scale);
                return scale;
            }
            set
            {
                VC.KWG_LAYER_SET_MAXSCALE(base.m_InPtr, value);
            }
        }

        double ILayer.MinVisibleScale
        {
            get
            {
                double scale = 0;
                VC.KWG_LAYER_GET_MINSCALE(base.m_InPtr, ref scale);
                return scale;
            }
            set
            {
                VC.KWG_LAYER_SET_MINSCALE(base.m_InPtr, value);
            }
        }

        string ILayer.Name
        {
            get
            {
                StringBuilder builder = new StringBuilder(0x100);
                VC.KWG_LAYER_GET_NAME(base.m_InPtr, builder);
                return builder.ToString();
            }
        }

        LayerType ILayer.Type
        {
            get
            {
                return LayerType.KRasterLayer;
            }
        }

        bool ILayer.Visible
        {
            get
            {
                return VC.KWG_LAYER_GET_VISIBLE(base.m_InPtr);
            }
            set
            {
                VC.KWG_LAYER_SET_VISIBLE(base.m_InPtr, value);
            }
        }
    }
}

